package com.henu.cee_service.controller;

import com.henu.cee_service.entity.University;
import com.henu.cee_service.service.UniversityService;
import com.henu.cee_service.service.UserService;
import com.henu.cee_service.utils.DataResult;
import com.henu.cee_service.vo.req.*;
import com.henu.cee_service.vo.resq.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * description: UniversityController
 * date: 2020/7/22 16:33
 * author: JSM
 * version: 1.0
 */

@RestController
@RequestMapping("/v1")
@Api(tags = "学校模块相关接口")
public class UniversityController {

    @Autowired
    private UniversityService universityService;

    @PostMapping("/universities")
    @ApiOperation(value = "分页查询所有的学校")
    public DataResult<PageVO<University>> pageInfo(@RequestBody UniversityPageReqVO vo) {
        DataResult result = DataResult.success();
        result.setData(universityService.pageInfo(vo));
        return result;
    }

    @PostMapping("/province/universities")
    @ApiOperation(value = "通过省份名称分页查询学校")
    public DataResult<PageVO<University>> pageInfoByProvince(@RequestBody UniversityPageByProvinceReqVO vo) {
        DataResult result = DataResult.success();
        result.setData(universityService.pageInfoByProvince(vo));
        return result;
    }

    @GetMapping("/university/{id}")
    @ApiOperation(value = "查询学校详情")
    public DataResult<University> detailUniversity(@PathVariable("id") Long id) {
        DataResult result = DataResult.success();
        result.setData(universityService.selectById(id));
        return result;
    }

    @GetMapping("/universitybyname/{name}")
    @ApiOperation(value = "查询学校详情")
    public DataResult<University> detailUniversityByName(@PathVariable("name") String name) {
        DataResult result = DataResult.success();
        result.setData(universityService.selectByName(name));
        return result;
    }


    @DeleteMapping("/university/{id}")
    @ApiOperation(value = "删除学校")
    public DataResult<University> deletedUniversity(@PathVariable("id") Long id) {
        universityService.deleteUniversity(id);
        DataResult result = DataResult.success();
        return result;
    }

    @PostMapping("/university")
    @ApiOperation(value = "新增学校")
    public DataResult<University> addUniversity(@RequestBody @Valid UniversityAddReqVO vo) {
        universityService.addUniversity(vo);
        DataResult result = DataResult.success();
        return result;
    }

    @PutMapping("/university")
    @ApiOperation(value = "更新学校详情")
    public DataResult<University> updateUniversity(@RequestBody UniversityUpdateReqVO vo) {
        universityService.updateUniversity(vo);
        DataResult result = DataResult.success();
        return result;
    }

    @PostMapping("/score/universities")
    @ApiOperation(value = "根据考生分数查询可能被录取的学校")
    public DataResult<PageVO<University>> schoolsByScoer(@RequestBody UniversityPageByScoreReqVO vo) {
        DataResult result = DataResult.success();
        result.setData(universityService.pageInfoByScore(vo));
        return result;
    }

}
